//
//  weibonetwork+extension.swift
//  weibo
//
//  Created by jason on 2017/3/5.
//  Copyright © 2017年 jason. All rights reserved.
//

import Foundation

extension weibonetwork{
   //since_id	false	int64	若指定此参数，则返回ID比since_id大的微博（即比since_id时间晚的微博），默认为0。
    //max_id	false	int64	若指定此参数，则返回ID小于或等于max_id的微博，默认为0。
    //刷新数据
    func statuslist(since_id:Int64,max_id:Int64,completion:@escaping (_ list:[[String:AnyObject]]?,_ issuccess:Bool)->()){
        let url = "https://api.weibo.com/2/statuses/home_timeline.json?"
        
        let params = ["since_id":"\(since_id)" as AnyObject, "max_id":"\(max_id > 0 ? max_id - 1 : 0)" as AnyObject]
        tokenrequest(URLString: url, parameters: params ){ (json, issueccess) in
            let result = json?["statuses"] as? [[String : AnyObject]]
            completion(result,true)
        }
    }
    //获取用户未读数目
    func unreadcount(completion:@escaping (_ cont:Int)->()){
        guard let uid = uid else{
            return
        }
        let urlstring = "https://rm.api.weibo.com/2/remind/unread_count.json"
        let parms = ["uid":uid as AnyObject]
        tokenrequest(URLString: urlstring, parameters: parms ) { (json, issuccess) in
            let dict = json as? [String:AnyObject]
            let count = dict?["status"] as? Int
            completion(count ?? 0)
        }
    }
}
